var swiper = new Swiper(".mySwiper1", {
    navigation: {
        nextEl: ".swiper-button-next",
        prevEl: ".swiper-button-prev",
    },
    loop: true,
    autoplay: true,
});
$(function () {
    // 登录按钮处理
    var curUser = JSON.parse($.cookie('User'));
    var curCar = JSON.parse($.cookie('Car'));
    if (curUser == null) {
        $('#nav .user a:eq(0)').text('登录').attr('href', './login.html');
        $('#nav .user a:eq(1)').text('购物车').attr('href', './login.html');
    } else {
        $('#nav .user a:eq(0)').text(curUser.username).attr('href', '#')
        $('#nav .user a:eq(1)').text(`购物车`).attr('href', './car.html')
    }
    // 购物车按钮判断
    $('#nav .user a:eq(1)').on('click',function(e) {
        e.preventDefault();
        if($(this).attr('href') == './login.html'){
            layer.alert(
                '您还没有登录请先登录',
                {   icon: 0, 
                    shadeClose: true, 
                    title: '消息',
                },
                function(){
                    location.href='../login.html'
                },
            );
        } else {
            location.href='../car.html'
        }
    })
    // 初始化页面
    function init() {
        var str = '';
        $.each(shoes, function (i, item) {
            str = `<div class="swiper-slide">
                <a href="./detail.html?id=${item.id}">
                    <img src="${item.src}" alt="">
                </a>
                <p>
                    <a href="./detail.html?id=${item.id}">
                        ${item.name}
                    </a>
                </p>
                <p>
                    <a href="./detail.html?id=${item.id}">
                        ${item.price}
                    </a>
                </p>
            </div>`
            $('#trend .swiper-wrapper').append(str)
            $('#newShop .swiper-wrapper').append(str)
        });
    }
    init();
    var mySwiper3 = new Swiper(".mySwiper3", {
        slidesPerView: 5,
        spaceBetween: 20,
        slidesPerGroup: 5,
        loop: true,
        autoplay: true,
        loopFillGroupWithBlank: true,
        navigation: {
            nextEl: ".swiper-button-next",
            prevEl: ".swiper-button-prev",
        },
    });
    var swiper2 = new Swiper(".mySwiper2", {
        slidesPerView: 5,
        spaceBetween: 20,
        slidesPerGroup: 5,
        loop: true,
        loopFillGroupWithBlank: true,
        navigation: {
            nextEl: ".swiper-button-next",
            prevEl: ".swiper-button-prev",
        },
        autoplay: true,
    });
})